import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */
import systemRouter from './modules/system'
import spRouter from './modules/sp'
import mchRouter from './modules/mch'

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    name: 'Redirect',
    path: '/redirect',
    component: Layout,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    name: 'Login',
    path: '/login',
    component: () => import('@/views/login/index')
  },
  {
    name: 'zfbPay',
    path: '/zfbPay',
    component: () => import('@/views/pay/zfbPay')
  },
  {
    name: 'AuthRedirect',
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect')
  },
  {
    name: '404',
    path: '/404',
    component: () => import('@/views/error-page/404')
  },
  {
    name: '401',
    path: '/401',
    component: () => import('@/views/error-page/401')
  }

]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  {
    name: 'layout',
    path: '/',
    component: () => import('@/layout/index'),
    children: [
      ...systemRouter,
      ...spRouter,
      ...mchRouter
    ]
  },
  {
    name: 'LoginPlatform',
    path: '/login-platform',
    component: () => import('@/views/login-platform')
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export default router
